package com.zwj.batch.core.batch.step;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * step 实现类
 *
 * @author 张文接
 * @version 1.0
 * @createTime 2024/3/6 16:52
 */
@Slf4j
@Component
public class BatchStep {
    /**
     * step构建工厂
     */
    @Resource
    private StepBuilderFactory stepBuilderFactory;

    /**
     * 使用 tasklet 去实现批处理逻辑
     *
     * @return step
     */
    public Step test1Step1() {
        return stepBuilderFactory
                .get("test1Step1")
                .tasklet((stepContribution, chunkContext) -> {
                    Map<String, Object> jobParameters = chunkContext.getStepContext().getJobParameters();
                    log.error("===========hello springBatch==============");
                    log.error("===========name: {}==============",jobParameters.get("name"));
                    return RepeatStatus.FINISHED;
                }).build();
    }
}
